#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>

#define fatal(test) do {if (test) {printf ("trash: %s\n", strerror(errno)); \
                       exit(EXIT_FAILURE);}} while(0)

int
main (int argc, char **argv)
{
  int pid, status;
  int f, c;


  printf ("Starting...\n");

  f = 5;
  c = 10;

  pid = fork ();
  fatal (pid<0);
  
  if (pid>0)
    {
      while (f--)
	{
	  printf ("%d F: (pid %5d, father pid %d) my pid %d\n", f, pid, getppid(), getpid());
	  sleep(1);
	}
      
      printf ("F - waiting for child\n");
      wait (&status);
      printf ("F - my child finished with status %d\n", status);
      sleep(4);
      printf ("* Father finished\n");

    }
  else
    {
      while (c--)
	{
	  printf ("%d c: (pid %5d, father pid %d) my pid %d\n", c, pid, getppid(), getpid());
	  sleep(1);
	}
      printf ("* Child finished\n");

    }
  

  return EXIT_SUCCESS;
}
